/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-04-23
 * Time:10:19
 */
public class Demo15 {

    public static int num = 0;

    synchronized public static void increase(){
        num++;
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                increase();
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                increase();
            }
        });
        t1.start();//启动线程
        t2.start();
        t1.join();//让main等待
        t2.join();
        //t1、t2都执行结束后
        System.out.println(num);
    }
}
